//
//  HomeTradingOfCharactersTableViewCell.m
//  gamebox_qpp
//
//  Created by 赵隆杰 on 2022/12/6.
//

#import "HomeTradingOfCharactersTableViewCell.h"
#import "HomeTradingOfCharactersSubView.h"
#import "GameDetailViewController.h"

#define SubViewWidth (SL_WINDOW_WIDTH/4)

@interface HomeTradingOfCharactersTableViewCell ()

@property(nonatomic, strong) UIScrollView *scrollView;

@property (nonatomic, strong) NSArray <GameDetailNewModel*>*correlationGames;

@end

@implementation HomeTradingOfCharactersTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.scrollView = [[UIScrollView alloc] init];
    [self.contentView addSubview:self.scrollView];
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
}

- (void)initCellData0:(NSArray<GameDetailNewModel *> *)array
{
    [self.scrollView removeAllSubviews];
    if (array.count == 0) {
        return;
    }
    for (NSInteger i = 0; i < array.count; i++) {
        HomeTradingOfCharactersSubView *subView = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([HomeTradingOfCharactersSubView class]) owner:self options:nil].firstObject;
        subView.detailModel = array[i];
        [self.scrollView addSubview:subView];
        [subView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(SubViewWidth);
            make.height.equalTo(self.scrollView);
            make.left.mas_equalTo(4 + (SubViewWidth + 10) * i);
            make.top.mas_equalTo(0);
        }];
        VHWeakSelf
        [subView addTapBlock:^(id  _Nonnull obj) {
            VHStrongSelf
            GameDetailViewController *vc = [[GameDetailViewController alloc] init];
            vc.modelId = @"1";
            [[UIWindow currentViewController].navigationController pushViewController:vc animated:YES];
        }];
    }
    CGFloat scrollSizeWidth = 4 + (SubViewWidth + 10) * array.count + 4;
    if (scrollSizeWidth < SL_WINDOW_WIDTH) {
        scrollSizeWidth = SL_WINDOW_WIDTH;
    }
    [self.scrollView setContentSize:CGSizeMake(scrollSizeWidth, 0)];
    
    
}

@end
